﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Kinect;
using BicycleTrafficSimulator.DataModel;
using System.Threading;

namespace BicycleTrafficSimulator
{
    public class Bike : AbstractModel, IGameObject
    {
        private BoundingSphere boundingSphere;

        public BoundingSphere BoundingSphere
        {
            get { return boundingSphere; }
            set { boundingSphere = value; }
        }
         public Bike()
        {
            this.Position = new Vector3(3.5f, 0.015f, -3.5f);
            this.Rotation = 300.0f;
        }

         public void LoadContent(ContentManager content, String modelName)
         {
             this.Model = content.Load<Model>(modelName);
         }

         public void Update(GameTime gameTime)
         {
             BoundingSphere = new BoundingSphere(this.Position, 0.03f);
         }

         public void Draw(Matrix viewMatrix, Matrix projectionMatrix)
         {
             // Vector3 addVector = Vector3.Transform(new Vector3(1, 0, 0), xwingRotation); 
             Matrix worldMatrix = Matrix.CreateScale(0.0016f, 0.0016f, 0.0016f) * Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateRotationY(this.Rotation) * Matrix.CreateTranslation(this.Position);
             // Copy any parent transforms.
             Matrix[] transforms = new Matrix[this.Model.Bones.Count];
             this.Model.CopyAbsoluteBoneTransformsTo(transforms);


             // Draw the model. A model can have multiple meshes, so loop.
             foreach (ModelMesh mesh in this.Model.Meshes)
             {

                 // This is where the mesh orientation is set, as well 
                 // as our camera and projection.
                 foreach (BasicEffect effect in mesh.Effects)
                 {
                     effect.EnableDefaultLighting();
                     effect.World = transforms[mesh.ParentBone.Index] *
                         worldMatrix;
                     effect.View = viewMatrix;// Matrix.CreateLookAt(new Vector3(20, 13, -5), new Vector3(8, 0, -7), new Vector3(0, 1, 0));
                     effect.Projection = projectionMatrix;
                     effect.DiffuseColor = new Vector3(0, 0, 0.2f);
                 }
                 // Draw the mesh, using the effects set above.
                 mesh.Draw();
             }
         }
    }
}
